# 根目录 CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(asio_game_server)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 查找必要的包
find_package(Boost REQUIRED COMPONENTS system)
find_package(Threads REQUIRED)
find_package(nlohmann_json REQUIRED)

# hiredis
find_library(HIREDIS_LIBRARY NAMES hiredis)
find_path(HIREDIS_INCLUDE_DIR NAMES hiredis/hiredis.h)

# MySQL
# 手动定位MySQL头文件
find_path(MYSQL_INCLUDE_DIR  NAMES mysql/mysql.h)

if (NOT MYSQL_INCLUDE_DIR)
    message(FATAL_ERROR "MySQL include directory not found!")
endif()

# 手动定位MySQL客户端库
find_library(MYSQL_LIBRARIES
  NAMES mysqlclient libmysqlclient libmariadb           # Linux
)

if (NOT MYSQL_LIBRARIES)
    message(FATAL_ERROR "MySQL client library not found!")
endif()

# 验证是否找到必要组件
# 查找 spdlog 库
find_package(spdlog REQUIRED)

if(NOT HIREDIS_LIBRARY OR NOT HIREDIS_INCLUDE_DIR)
    message(FATAL_ERROR "hiredis library not found")
endif()

# OpenSSL
find_package(OpenSSL REQUIRED)

#设置输出路径
set(EXECUTABLE_OUTPUT_PATH  ${CMAKE_CURRENT_BINARY_DIR}/bin)

# 添加子目录
add_subdirectory(src) 
add_subdirectory(tests)